<%--
  Created by IntelliJ IDEA.
  User: uyijk
  Date: 2021/9/9
  Time: 14:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        .table1 {
            width: 70%;
        }
        #query-form{
            width: 60%;
            margin: 50px;
        }
        #delBtn{
            margin-left: 20px;
        }

        #query-btn{
            margin-left: -60px;
        }

    </style>
    <script>
        $(function(){
            //全选、反选功能
            $("#chk1").click(function(){
                var st = $("#chk1").prop('checked');
                $(":checkbox").prop("checked",st);
            })
            //点击删除按钮，让表单提交
            $("#delBtn").click(function(){
                //判断有没有复选框选中
                var length = $("input:checked").length;
               if(length>0) {
                   $("#del-form").submit();
               }else{
                   alert("请选择要删除的学生");
               }
            });

        });
    </script>
</head>
<body>
<center>
    <form class="form-horizontal" id="query-form" role="form" action="${pageContext.request.contextPath}/student/queryByName" method="post" >
        <div class="form-group">
            <div class="col-sm-9">
                <input type="text" class="form-control" id="firstname"
                       placeholder="请输入名字" name="name">

            </div>
            <input type="submit" id="query-btn"  class="btn btn-default" value="查询">
            <input type="button" id="delBtn" class="btn btn-danger" value="删除"/>
        </div>
    </form>

    <table class="table table1 table-hover">
        <thead>
        <tr>
            <th><input type="checkbox" id="chk1"/></th>
            <th>编号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>修改</th>
        </tr>
        </thead>
        <form id="del-form" method="post" action="${pageContext.request.contextPath}/student/delete">
        <tbody>
        <c:forEach items="${students}" var="student">
            <tr>
                <td><input type="checkbox" name="id" value="${student.id}"/></td>
                <td>${student.id}</td>
                <td>${student.name}</td>
                <td>${student.age}</td>
                <td>
                    <a href="${pageContext.request.contextPath}/student/queryById?id=${student.id}">
                     <input type="button" value="修改" class="btn btn-warning"/>
                    </a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
        </form>
    </table>
</center>
</body>
</html>
